<?php
/*
 * @Author: your name
 * @Date: 2020-04-24 13:41:08
 * @LastEditTime: 2020-04-28 16:26:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \ztaudio-activity\app\Http\Controllers\BoatController.php
 */

namespace App\Http\Controllers;

use App\Http\Model\Config;
use App\Http\Model\Gift;
use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Model\User;
use App\Http\Model\UserM;
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\AudioApi;
use Illuminate\Support\Facades\DB;

/*
 *
 * */

class WishingTreeController extends BaseController
{
    protected $model;
    protected $configModel;
    protected $gift_model;
    protected $user_model;
    private $audioApi;

    protected $table = 'gift_boat_ticket_log';

    public function __construct()
    {
        $this->gift_model = new Gift();
        $this->user_model = new UserM();
        $this->audioApi = new AudioApi();

    }

    /**
     * 使用锤子
     *
     * @param Request $request
     * @param 
     * @param 
     * @return void
     */
    public function ticketUsed(Request $request)
    {
        $res = $request->post('data');
        if(is_object($res)) {  
            $res = (array)$res;  
        } 
        if($res['code'] === 0){
            $new = array();
            foreach ($res['data'] as $k=>$v){
                if(isset($new[$v['gift_id']])){
                    $new[$v['gift_id']]['num'] += 1;
                    
                }else{
                    $new[$v['gift_id']]['num'] = 1;
                }
                $new[$v['gift_id']]['gift_id'] = $v['gift_id'];
                $new[$v['gift_id']]['goods_id'] = $v['gift_id'];
                $new[$v['gift_id']]['name'] = $v['name'];
                $new[$v['gift_id']]['image'] = $v['image'];
                $new[$v['gift_id']]['price'] = $v['price'];
            }
            sort($new);
            $res['data'] = $new;
        }
        
        return $res;
    }

}
